import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;

import org.springframework.util.StringUtils;

public class PageTemplateFormat {

	public static void main(String[] args) {
		File fileDir = new File("D:\\Git\\generate-code\\template\\page\\inline-add");
		for (File file : fileDir.listFiles()) {
			if(file.getName().endsWith(".vue")) {
				try (BufferedReader fileReader = new BufferedReader(new FileReader(file));
						FileWriter templateFileWriter = new FileWriter( new File(file.getName() + ".ftl"))){
					String str = null;
					int lineCount = 1;
					while((str = fileReader.readLine()) != null) {
						if(str.indexOf("${requestPrefix}") != -1) {
							str = StringUtils.replace(str, "${requestPrefix}", "${r'${requestPrefix}'}");
						}else if(str.startsWith("const requestPrefix")){
							str = "const requestPrefix = 'http://localhost:8080${extParam.REQUEST_PREFIX!}/${module.name ? uncap_first}'";
						}else if(str.startsWith("const requestPrefixTree")){
							str = "const requestPrefixTree = 'http://localhost:8080${extParam.REQUEST_PREFIX!}/${module.name ? uncap_first}/Tree'";
						}else if(str.indexOf("LHG") != -1){
							System.out.println(lineCount);
						}
						templateFileWriter.write(str);
						lineCount++;
					}
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
}
